<!DOCTYPE html>
<html lang="en" xmlns="http://www.thymeleaf.org">
<head>
    <title>Title</title>
    <link rel="stylesheet" th:href="@{http://maxcdn.bootstrapcdn.com/font-awesome/4.3.0/css/font-awesome.min.css}">
    <link rel="stylesheet" th:href="@{assets/css/core.css}"/>
    <link rel="stylesheet" th:href="@{assets/css/amazeui.css}"/>
    <link rel="stylesheet" th:href="@{assets/css/menu.css}"/>
    <link rel="stylesheet" th:href="@{assets/css/index.css}"/>
    <link rel="stylesheet" th:href="@{assets/css/admin.css}"/>
    <link rel="stylesheet" th:href="@{assets/css/page/typography.css}"/>
    <link rel="stylesheet" th:href="@{assets/css/page/form.css}"/>
    <link rel="stylesheet" th:href="@{assets/css/component.css}"/>

    <link rel="stylesheet" th:href="@{https://cdn.staticfile.org/twitter-bootstrap/3.3.7/css/bootstrap.min.css}">
    <script th:src="@{https://cdn.staticfile.org/jquery/2.1.1/jquery.min.js}"></script>
    <script th:src="@{https://cdn.staticfile.org/twitter-bootstrap/3.3.7/js/bootstrap.min.js}"></script>


    <!-- Favicons -->
    <link rel="icon" th:href="@{img/favicon.png}"/>
    <link rel="apple-touch-icon" th:href="@{img/apple-touch-icon.png}"/>

    <!-- Bootstrap core CSS -->
    <link rel="stylesheet" th:href="@{lib/bootstrap/css/bootstrap.min.css}"/>

    <!--external css-->
    <link rel="stylesheet" th:href="@{lib/font-awesome/css/font-awesome.css}"/>
    <link rel="stylesheet" type="text/css" th:href="@{css/zabuto_calendar.css}"/>
    <link rel="stylesheet" type="text/css" th:href="@{lib/gritter/css/jquery.gritter.css}"/>

    <link rel="stylesheet" th:href="@{css/style.css}"/>
    <link rel="stylesheet" th:href="@{css/style-responsive.css}"/>
    <script th:src="@{lib/chart-master/Chart.js}"></script>

</head>
<body style="overflow-y:scroll;">

<section id="container">
    <!--header start-->
    <header class="header black-bg" th:replace="headBar::myHeadBar">
    </header>
    <!--header end-->

    <!--sidebar start-->
    <aside th:replace="leftSideBar::myLeftBar">
    </aside>
    <!--sidebar end-->

    <!--right begin-->

    <!--main content start-->
    <section id="main-content">
        <section class="wrapper">
            <h3><i class="fa fa-angle-right"></i> 厂商管理</h3>
            <div class="row">
                <div class="col-md-12">
                    <div class="content-panel">
                        <button class="btn btn-sm btn-success" id="viewDeleteFactory" data-toggle="modal"
                                data-target="#deleteFactoryModal" style="margin-left: 20px;">已删除列表
                        </button>
                        <span id="addF"></span>
                        <table class="am-table am-table-striped am-table-hover table-main"
                               style="border-top: ridge;margin-top: 15px;">
                            <thead>
                            <tr>
                                <th><i class="table-id"></i> ID</th>
                                <th class="table-title"><i class="fa fa-question-circle"></i> 厂商名称</th>
                                <th id="action" style="display:none"><i class=" fa fa-edit"></i> 操作</th>
                                <th></th>
                            </tr>
                            </thead>
                            <tbody>

                            <tr th:each="factory : ${factoryList}">
                                <td th:text="${factoryStat.count}+(${curPage}-1)*${pageSize}">
                                </td>
                                <td class="hidden-phone" th:text="${factory.name}"></td>
                                <td>
                                    <a class="btn btn-primary btn-xs updateBtn" id="myedit"
                                       data-toggle="modal" data-target="#addModal" style="display:none"
                                       th:onclick="'getId('+${factory.id}+')'"><i
                                            class="fa fa-pencil"> 编辑</i>
                                    </a>

                                    <button class="btn btn-danger btn-xs deleteBtn" id="mydelete"
                                            th:attr="del_uri=@{/deleteF}+${factory.name}" style="display:none"
                                    ><i class="fa fa-trash-o "> 删除</i>
                                    </button>
                                </td>
                            </tr>

                            </tbody>
                            <div class="span6">
                                <div class="dataTables_paginate paging_bootstrap pagination">
                                    <table style="float: right">
                                        <tr>
                                           <td>
                                            <span th:if="${curPage <=1}">
                                                <ul class="pager">
                                                   <li><a >首页</a></li>
                                                   <li><a >上一页</a></li>
                                                  </ul>

                                                </span>
                                           </td>
                                                                 <!--     <td> 首页</td>
                                                               <td cosplan="2">上一页</td>-->



                                            <td>
                                            <span th:if="${curPage > 1}">
                                                 <ul class="pager">
                                                   <li><a th:href="@{/factory}">首页</a></li>
                                                   <li><a th:href="@{'/factory?curPage='+${curPage-1}}">上一页</a></li>
                                                  </ul>
                                            </span>
                                            </td><!--  <td> <a th:href="@{/factory}">首页</a>

                                                             <td> <a th:href="@{'/factory?curPage='+${curPage-1}}"
                                                                     cosplan="2">上一页</a>-->

                                            <td>
                                            <span th:if="${curPage == totalPages}">
                                                 <ul class="pager">
                                                   <li><a>下一页</a></li>
                                                   <li><a >尾页</a></li>
                                                  </ul>
                                            </span>           <!-- <td cosplan="2"> 下一页</td>                                                               <td>尾页</td>-->
                                            </td>

                                            <td>
                                            <span th:if="${curPage < totalPages}">
                                                 <ul class="pager">
                                                   <li><a th:href="@{'/factory?curPage='+${curPage+1}}">下一页</a></li>
                                                   <li><a th:href="@{'/factory?curPage='+${totalPages}}">尾页</a></li>
                                                  </ul>

                                            </span>
                                            </td>
                                                           <!--   <td> <a th:href="@{'/factory?curPage='+${curPage+1}}"
                                                                      cosplan="2">下一页</a></td>
                                                              <td> <a th:href="@{'/factory?curPage='+${totalPages}}">尾页</a></td>-->

                                        </tr>
                                    </table>

                                </div>

                            </div>

                        </table>
                        <div class="span6">
                               <!-- <div class="dataTables_info" id="hidden-table-info_info" style="margin-left: 20px">
                                    共 <span th:text="${totalRows}"></span> 条记录
                                    当前是第<span th:text="${curPage}"></span>页
                                </div>-->
                            </div>

                        <div style="margin-left: 20px;float: left;margin-top: -41px;color: #101010;">
                            共 <span th:text="${totalRows}"></span> 条记录
                            当前是第<span th:text="${curPage}"></span>页
                        </div>

                    </div>
                </div>
                <!-- /content-panel -->
            </div>
            <!-- /col-md-12 -->
            <!-- /row -->
        </section>
    </section>
    <!-- /MAIN CONTENT -->
    <!--main content end-->
    <form id="deleteForm" method="get" action="">
        <input type="hidden" name="_method" value="delete">
    </form>

    <form id="rebackForm" method="get" action="">
        <input type="hidden" name="_method" value="reback">
    </form>
    <!--right end-->


    <!--删除列表模态框-->

    <div class="modal fade" id="deleteFactoryModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel"
         aria-hidden="true">
        <div class="modal-dialog">
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                    <h4 class="modal-title" id="myModalLabel">已删除的厂商</h4>
                </div>
                <div class="modal-body">
                    <table class="table">
                        <thead>
                        <tr>
                            <th>
                                编号
                            </th>
                            <th>
                                名称
                            </th>
                            <th>
                                操作
                            </th>

                        </tr>
                        </thead>
                        <tbody>
                        <tr th:each="del_factory : ${del_factoryList}">
                            <td th:text="${del_factoryStat.count}">
                            </td>
                            <td class="hidden-phone" th:text="${del_factory.name}"></td>
                            <td>
                                <button class="btn btn-sm btn-success backBtn" id="reback"
                                        th:attr="reb_uri=@{/rebackF}+${del_factory.name}">恢复
                                </button>
                            </td>
                        </tr>

                        </tbody>
                    </table>


                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
                    <!-- <button type="button" class="btn btn-primary">提交更改</button>-->
                </div>
            </div><!-- /.modal-content -->
        </div><!-- /.modal -->
    </div>


</section>
<!-- navbar -->
<a th:href="@{admin-offcanvas}" class="am-icon-btn am-icon-th-list am-show-sm-only admin-menu"
   data-am-offcanvas="{target: '#admin-offcanvas'}"><!--<i class="fa fa-bars" aria-hidden="true"></i>--></a>

<script type="text/javascript" th:src="@{assets/js/jquery-2.1.0.js}"></script>
<!--<script type="text/javascript" th:src="@{assets/js/app.js}"></script>-->
<script type="text/javascript" th:src="@{assets/js/blockUI.js}"></script>
<!--<script type="text/javascript" th:src="@{assets/js/charts/echarts.min.js}"></script>
<script type="text/javascript" th:src="@{assets/js/charts/indexChart.js}"></script>-->
<script type="text/javascript" th:src="@{assets/js/amazeui.min.js}"></script>

<!--添加或者更新厂商-->
<script type="text/javascript" th:inline="javascript">
    var URL = [[@{
        /factoryCheck}]];
        var URL2 = [[@{
            /addF}]];

            function checkName() {
                var inputName = $("#factoryName").val();
                if (inputName != null) {
                    $.ajax({
                        type: "get",
                        url: URL,
                        data: {name: inputName},
                        success: function (data) {
                            if (0 < parseInt(data)) {

                                $("#saveFactory").attr("disabled", true);
                                $("#msg").html(" \"<span style='color:red'>厂商名重复！</span>\"");
                            } else {
                                $("#saveFactory").attr("disabled", false);
                                $("#msg").html("\"<span style='color:blueviolet'>厂商名可用！</span>\"");

                            }
                            console.log(data);
                        }
                    });
                }
            };

            function addFact() {
                var inputName = $("#factoryName").val();
                var id=$("#updateId").val();
                if (inputName != null) {
                    $.ajax({
                        type: "get",
                        url: URL2,
                        data: {name: inputName,ID:id},
                        success: function (data) {
                            $('#close').click();
                            if (data.data) {
                                alert("更新成功");
                                window.location.href = "/factory";
                            } else {
                                alert(data.message)
                            }
                            console.log(data);
                        }
                    });

                }
            };
</script>

<script type="text/javascript" th:inline="javascript">
    $(function () {
        var URL = [[@{
            /headPic}]];
            $.ajax({
                type: "get",
                url: URL,
                data: {},
                success: function (data) {
                    console.log(data);
                    $("#headPic").attr("src", "data:image/gif;base64," + data);
                }
            });
        }
    );


</script>

<!--删除 和编辑-->
<script type="text/javascript" th:inline="javascript">

    function showModel() {
        alert("test");
        $("#modal-container-371501").modal("show");
    }


    $(".deleteBtn").click(function deleteUser() {

        if (confirm("确定删除吗")) {
            $("#deleteForm").attr("action", $(this).attr("del_uri")).submit();
            alert("删除成功");
            return false;
        } else {
            return false;
        }
        /* $("#deleteForm").attr("action", $(this).attr("del_uri")).submit();
         return false;*/
    });

    $("#addModal").modal("hide");


    function getId(ID) {
        console.log(ID);
        getFactory(ID);
        $("#updateId").val(ID);

    }

    function getFactory(ID) {
        var URL = [[@{
            /getF}]];
            $.ajax({
                type: "get",
                url: URL,
                data: {
                    id: ID
                },
                success: function (data) {
                    console.log(data);
                    if (data != null || data != " ") {
                        $("#factoryName").val(data)
                    }
                }
            });
        }


</script>

<!--验证登陆者的主题主题上传权限-->

<script type="text/javascript" th:inline="javascript">
    $(function () {
        var URL = [[@{
            /checkPermission}]];
            var add = "上传";
            $.ajax({
                type: "get",
                url: URL,
                data: {
                    action: add
                },
                success: function (data) {
                    console.log(data);
                    if (0 < parseInt(data)) {
                        $("#uploadTheme").show();
                    } else {

                        $("#uploadTheme").hide();
                    }
                }
            });
        }
    )


</script>

<!--验证登陆者的主题主题查看权限-->

<script type="text/javascript" th:inline="javascript">
    $(function () {
        var URL = [[@{
            /checkPermission}]];
            var view = "查看";
            $.ajax({
                type: "get",
                url: URL,
                data: {
                    action: view
                },
                success: function (data) {
                    console.log(data);
                    if (0 < parseInt(data)) {
                        $("#viewTheme").show()
                    } else {

                        $("#viewTheme").hide()
                    }
                }
            });
        }
    )


</script>


<!--验证登陆者的角色权限-->
<script type="text/javascript" th:inline="javascript">
    $(function () {
        var URL = [[@{
            /checkRole}]];
            $.ajax({
                type: "get",
                url: URL,
                data: {},
                success: function (data) {
                    console.log(data);
                    if (0 < parseInt(data)) {
                        var url = [[@{
                            /user}]]
                            $("#myUser").html('<a href="' + url + '" >\n' +
                                '                        <i class="fa fa-desktop"></i>\n' +
                                '                        <span >用户管理</span>\n' +
                                '                    </a>');

                            $("#addF").html(' <button class="btn btn-sm btn-success" id="addFactory" data-toggle="modal" data-target="#addModal" style="margin-left: 20px;" >\n' +
                                '                            新增</button>');

                            $("#action").show();
                            $(".updateBtn").show();
                            $(".deleteBtn").show();

                            /* $("#addFactory").show();*/
                            $("#userManager").show()
                        }
                    else
                        {

                            $("#action").hide();
                            $(".updateBtn").hide();
                            $(".deleteBtn").hide();
                            $("#userManager").hide();
                            /* $("#addFactory").hide();*/
                        }
                    }
                });
        }
    )


</script>

<!--恢复删除的厂商-->
<script type="text/javascript" th:inline="javascript">
    $(".backBtn").click(function rebackFactory() {
        if (confirm("确定恢复吗")) {
            $("#rebackForm").attr("action", $(this).attr("reb_uri")).submit();
            alert("恢复成功");
            return false;
        } else {
            return false;
        }
        /* $("#deleteForm").attr("action", $(this).attr("del_uri")).submit();
         return false;*/
    })

</script>

<!--编辑模态框-->
<div class="modal fade" id="addModal" tabindex="-1" role="dialog"
     aria-labelledby="myModalLabel" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" id="close" data-dismiss="modal"
                        aria-hidden="true">
                    &times;
                </button>
                <h4 class="modal-title" id="myModalLabel">
                    厂商
                </h4>
            </div>
            <div class="modal-body">

                <input type="hidden" id="updateId" name="updateId" value=""/>  <!--隐藏框-->

                <div class="form-group">
                    <label for="lastname"
                           class="col-sm-3 control-label ">厂商名:</label><span
                        id="msg"></span>
                    <input type="text" class="form-control" name="factoryName"
                           value="" id="factoryName"
                           placeholder="厂商名" oninput="checkName()">

                </div>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal">关闭
                </button>
                <button type="button" class="btn btn-primary" id="saveFactory" onclick="
                                            addFact()">
                    提交
                </button>
            </div>
        </div><!-- /.modal-content -->
    </div><!-- /.modal -->
</div><!-- /.modal end -->


<!-- js placed at the end of the document so the pages load faster -->
<script th:src="@{lib/jquery/jquery.min.js}"></script>

<script th:src="@{lib/bootstrap/js/bootstrap.js}"></script>
<script class="include" type="text/javascript" th:src="@{lib/jquery.dcjqaccordion.2.7.js}"></script>
<script th:src="@{lib/jquery.scrollTo.min.js}"></script>
<script th:src="@{lib/jquery.nicescroll.js}" type="text/javascript"></script>
<script th:src="@{lib/jquery.sparkline.js}"></script>
<!--common script for all pages-->
<script th:src="@{lib/common-scripts.js}"></script>
<script type="text/javascript" th:src="@{lib/gritter/js/jquery.gritter.js}"></script>
<script type="text/javascript" th:src="@{lib/gritter-conf.js}"></script>
<!--script for this page-->
<script th:src="@{lib/sparkline-chart.js}"></script>
<script th:src="@{lib/zabuto_calendar.js}"></script>

<!--获取头像-->
<script type="text/javascript" th:inline="javascript">
    $(function () {
        var URL = [[@{
            /headPic}]];
            $.ajax({
                type: "get",
                url: URL,
                data: {},
                success: function (data) {
                    console.log(data);
                    $("#headPic").attr("src", "data:image/gif;base64," + data);
                }
            });
        }
    );


</script>


</body>

</html>